package cn.web.model;

import cn.entity.Article;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author m on 2023/1/28
 * Description:
 */
@Getter
@Setter
public class VmArticle {
    private UUID id;
    private String title;
    private String content;
    private Integer commentSize;
    private Date createTime;
    private UUID userId;
    private String nickName;
    private String email;
    private List<String> tags;

    private VmArticle(){}

    public static VmArticle create(Article article){
        VmArticle vm = new VmArticle();
        vm.setId(article.getId());
        vm.setTitle(article.getTitle());
        vm.setContent(article.getContent());
        vm.setCommentSize(article.getCommentSize());
        vm.setCreateTime(article.getCreateTime());
        vm.setNickName(article.getUser().getNickName());
        vm.setUserId(article.getUser().getId());
        vm.setEmail(article.getUser().getEmail());

        List<String> ss = new ArrayList<>();
        article.getTags().forEach(tag -> ss.add(tag.getName()));
        vm.setTags(ss);
        return vm;
    }

}
